<?php namespace Common\Model;

use Hdphp\Model\Model;

class Brand extends Model{
	
	protected $table = "brand";
	
	protected $validate = array(
	
		array('bname','required','品牌名称不能为空',3,3),
	
	);
	
	
	protected $auto = array(
	
		array('logo','up','method',3,3),
	
	);
	
	public function up(){
		
		if($logo = Q('post.logo')) return $logo;
		
		$files = Upload::type('jpg,png,bmp')->size(2000000)->make();
		
		if($files){
			return $files[0]['path'];
		}else{
			if($_FILES['logo']['error'] !=4){
				$this->error = Upload::getError();
			}
			return '';
		}
	}
	
	public function addData(){
		if(!$this->create()) return false;
		if($this->error) return false;
		$this->add();
		return true;
	}
	
	public function editData(){
		if(!$this->create()) return false;
		if($this->error) return false;
		$this->save();
		return true;
	}
	
	
}


 ?>